package seed.service;

import java.sql.SQLException;
import java.util.List;


import seed.dao.SeedDao;
import seed.domain.Comment;
import seed.domain.Message;
import seed.domain.P_recommend;
import seed.domain.PageBean;
import seed.domain.Seed;
import user.domain.User;

public class SeedService {
     SeedDao seedDao = new SeedDao();
 /**
  * 鍒楀嚭鎵�鏈夋柟娉�
  * @param pc
  * @param ps
  * @return
  */
	public PageBean<Seed> findAll(int pc,int ps) {
		
		return seedDao.findAll(pc,ps);
	}
    /**
     * 鍔犺浇鍗曚釜璇︾粏
     * @param sname
     * @return
     */
	public Seed load(String sid) {
		return seedDao.load(sid);
	}
	/**
	 * 鎸夊垎绫绘煡璇㈠浘涔�
	 * @param cid
	 * @return
	 */
	public PageBean<Seed> findByCategory(String cid,int pc,int ps) {
		return (PageBean<Seed>) seedDao.findByCategory(cid, pc, ps);
	}
    /**
     * 瀵规瘮
     * @param sid
     * @return
     */
	public Seed getSeedBySid(String sid) {
		
		return seedDao.getSeedBySid(sid);
	}
   
	
	public User getUserByUid(String uid)
	{
		return seedDao.getUserByUid(uid);
	}
	public boolean addMessage(Message message){
		
		return seedDao.addMessage(message);
	}

	public List<Message> listMessage(){
		
		try {
			return seedDao.listMessage();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}
	public List<Seed> query(Seed creatia) {
		
		return seedDao.query(creatia);
	}
	public boolean addComment(Comment comment) {
		return seedDao.addComment(comment);
		
	}
	public List<Comment> commentMessage(String sid) throws SQLException {
		
		return seedDao.commentMessage(sid);
	}
	/////////////////////////////////////////////////////////////////////////////////////////////
	///////////////////////////////////////////////////////////////////////////////////////////////
	/*
	 * 
	 * 
	 * 
	 * 
	 * 
	 * 
	 * 
	 * 
	 * 后台方法
	 * 
	 * 
	 * 
	 * 
	 * 
	 */
	public void add(Seed seed) {
		 seedDao.add(seed);
		
	}
	
	public void delete(String sid) {
		seedDao.delete(sid);
		
	}
	public void messageDelete(String  messageId) {
		seedDao.messageDelete(messageId);
		
	}
	public void updateOverNumber(String sid){
		seedDao.updateOverNumber(sid);
	}
	public void addPersonalRecommend(String uid,String sid){
		P_recommend p= seedDao.isPersonalRecommend(uid, sid);
		if( p== null)
			seedDao.addPersonalRecommend(uid, sid);
		else 
			seedDao.updatePersonalRecommendNumber(p.getPrid());
	}
	public  List<P_recommend> getPersonalRecommend(String uid){
		return seedDao.getPersonalRecommend(uid);
	}
	
	
}
